package com.sumainfor.pc.epc.service.impl;

import com.google.common.collect.Lists;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ListMapMergeUtil;
import com.sumainfor.pc.epc.dao.FeignDecorateInfoMapper;
import com.sumainfor.pc.epc.dao.FeignDecorateMapper;
import com.sumainfor.pc.epc.feign.Housingauditfeign;
import com.sumainfor.pc.epc.feign.Zfeign.ZzuulFeign;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 * 装修套餐
 * @Auther: zhlu
 * @Date: 2018/12/17 10:33
 * @Description:
 */
@Service
public class FeignDecorateServiceImpl {

    @Autowired
    FeignDecorateMapper feignDecorateMapper;

    @Autowired
    FeignDecorateInfoMapper feignDecorateInfoMapper;

    @Autowired
    ZzuulFeign ZzuulFeign;

    @Autowired
    Housingauditfeign Housingauditfeign;

    Logger log= LoggerFactory.getLogger(FeignDecorateServiceImpl.class);


    public List<Map<String,Object>> getFeignDecorateList(){
        //查询装修套餐主表
        List<Map<String,Object>>getFeignDecorateList=feignDecorateMapper.getFeignDecorateList();
        for (Map<String,Object> map:getFeignDecorateList){
            List<Map<String,Object>>getDecorateComboInfo=feignDecorateInfoMapper.getDecorateComboInfo(new HashMap<String,Object>(){{
                put("CombId",map.get("CombId"));
            }});
            map.put("DecorateInfo",getDecorateComboInfo);
        }
        return getFeignDecorateList;
    }

    /**
     * 功能描述: 
     * 装修中房源列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/29 20:43
     */
    public List<Map<String,Object>>getDecorateHousingList(Map<String,Object>params){
        List<Map<String,Object>>getDecorateHousingList=feignDecorateMapper.getDecorateHousingList(params);

        //所有用户名称
        JsonResult jsonResult=ZzuulFeign.getAllUserIdAndName();
        List<Map<String,Object>>getAllUserIdAndName=(List<Map<String,Object>>)jsonResult.getResult();
        //根据用户编号合并
        getDecorateHousingList= ListMapMergeUtil.ListMergeUtils(getDecorateHousingList,getAllUserIdAndName,"userId");

        //获取所有的房源资料
        JsonResult jsonResult1=Housingauditfeign.getAllHousingArrList();
        List<Map<String,Object>>getAllHousingArrList=(List<Map<String,Object>>)jsonResult1.getResult();
        //根据用户编号合并
        getDecorateHousingList= ListMapMergeUtil.ListMergeUtils(getDecorateHousingList,getAllHousingArrList,"HouId");
        for(Map<String,Object> map:getDecorateHousingList){
            if(!StringUtils.isBlank(MapUtils.getString(map,"OwLoculus"))){
                if(!StringUtils.isBlank(MapUtils.getString(map,"OwHall"))){
                    if(!StringUtils.isBlank(MapUtils.getString(map,"OwGuard"))){
                        map.put("house",map.get("OwLoculus").toString()+"室"+map.get("OwHall").toString()+"厅"+map.get("OwGuard").toString()+"卫");
                    }else{
                        map.put("house",map.get("OwLoculus").toString()+"室"+map.get("OwHall").toString()+"厅");
                    }
                }else{
                    map.put("house",map.get("OwLoculus").toString()+"室");
                }
            }else{
                map.put("house",null);
            }
        }
        return getDecorateHousingList;
    }

    /**
     * 功能描述: 
     * 装修中房源列表总数
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/29 20:43
     */
    public Integer getDecorateHousingListCount(Map<String,Object>params){
        return feignDecorateMapper.getDecorateHousingListCount(params);
    }

}
